package com.shanjupay.merchant.service.impl;

import com.shanjupay.common.exception.BusinessException;
import com.shanjupay.common.exception.CommonErrorCode;
import com.shanjupay.common.util.QiniuUtils;
import com.shanjupay.merchant.service.FileService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.BatchUpdateException;

/**
 * @projectName: shanjupay
 * @package: com.shanjupay.merchant.service.impl
 * @className: FileServiceImpl
 * @author: Eric
 * @description: TODO
 * @date: 2023/12/4 9:38
 * @version: 1.0
 */
@Service
public class FileServiceImpl implements FileService {

    @Value("${oss.qiniu.accessKey}")
    private String accessKey;
    @Value("${oss.qiniu.secretKey}")
    private String secretKey;
    @Value("${oss.qiniu.bucket}")
    private String bucket;
    @Value("${oss.qiniu.prefixUrl}")
    private String prefixUrl;

    @Override
    public String upload(byte[] bytes, String fileName) {
        try {
            QiniuUtils.upload2Qiniu(accessKey,secretKey,bucket,bytes,fileName);
            return prefixUrl + fileName;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(CommonErrorCode.E_100106);
        }
    }
}
